package com.zqwm.fly.utils;


import com.zqwm.fly.types.Result;
import com.zqwm.fly.types.ResultType;

import java.util.Map;


@SuppressWarnings("all")
public class DataValidator {

    public static Result validateMapData(Map<String, Object> map, String... args)
    {
        Result result = new Result();
        result.setCode(ResultType.SUCCESS.getValue());

        if (null != args) {
            for (String arg : args) {
                if (arg.isEmpty()){
                    //如果参数为"",那么直接返回正确,不判断map的key
                    break;
                }
                boolean existArg = map.containsKey(arg);
                if (existArg == false)
                {
                    result.setCode(ResultType.EXCEPTION.getValue());
                    result.setMsg(arg + "参数为必填参数");
                    break;
                }else {
                    String value = map.get(arg).toString();
                    if("".equals(value))
                    {
                        result.setCode(ResultType.EXCEPTION.getValue());
                        result.setMsg(arg + "参数不能为空");
                        break;
                    }
                }
            }
        }

        return result;
    }
}
